package com.system.borrow.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.system.borrow.R;
import com.system.borrow.fragment.CapitalFragment;
import com.system.borrow.fragment.InfoFragment;
import com.system.borrow.fragment.UserFragment;
import com.system.borrow.utils.SecondTitle;

import java.util.ArrayList;
import java.util.List;

/**
 * 个人中心
 */
public class UserInfoActivity extends BaseActivity {
    private String[] titles = new String[]{"个人信息","身份信息","资产信息"};
    TabLayout sliding_tabs;
    ViewPager vp;
    private List<Fragment> fragments = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_info);
        SecondTitle title = new SecondTitle(this);
        title.setTitle("我的资料",null);
        initView();
    }

    private void initView() {
        sliding_tabs = (TabLayout) findViewById(R.id.sliding_tabs);
        vp = (ViewPager) findViewById(R.id.vp);
        UserFragment userFragment = new UserFragment();
        InfoFragment infoFragment = new InfoFragment();
        CapitalFragment capitalFragment = new CapitalFragment();
        fragments.add(userFragment);
        fragments.add(infoFragment);
        fragments.add(capitalFragment);
        FragmentPagerAdapter fragmentAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return titles[position];
            }
        };
        vp.setAdapter(fragmentAdapter);
        vp.setOffscreenPageLimit(3);
        sliding_tabs.setupWithViewPager(vp);
    }
}
